package com.example.it.review.acvitity.control;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

import com.example.it.review.R;

public class SeekBarActivity extends AppCompatActivity {

    private SeekBar seekBar;
    private TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_seek_bar);

        seekBar = (SeekBar) this.findViewById(R.id.seekBar);
        textView = (TextView) this.findViewById(R.id.tvInfo);
        init();
    }

    void init() {
        seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            /**
             * 当SeekBar的Progress改变的时候触发
             * @param  seekBar 控件
             * @param i  当前的进度
             * @param b  是否是被用户触发,因为我们通过代码来设置该属性的时候，也会触发此事件
             * */
            @Override
            public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
                textView.setText("Current " + i + " Total " + seekBar.getMax());
            }

            /**
             * 按住滑块的时候触发
             * */
            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                Toast.makeText(SeekBarActivity.this, "Touched", Toast.LENGTH_SHORT).show();
            }

            /**
             * 离开滑块的时候触发
             * */
            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                Toast.makeText(SeekBarActivity.this, "Untouch", Toast.LENGTH_SHORT).show();
            }
        });
    }
}
